package com.freesun.monitor.db;

/**
 * Created by yangfei on 13-12-6.
 */
public class OmariaDb {

    private ThreadGroup selectGroup;
    private ThreadGroup insertGroup;


    /**
     * @desc 一次请求启动10个线程转化为10次请求 查询操作
     * @param sql
     */
    public int multSelect(String sql,OperateMariaDb operateMariaDb){

        //创建查询线程组
        selectGroup = new ThreadGroup("select group");

        MultSelectMariaDb multSelectMariaDb1 =new MultSelectMariaDb(sql,operateMariaDb);
        MultSelectMariaDb multSelectMariaDb2 =new MultSelectMariaDb(sql,operateMariaDb);
        MultSelectMariaDb multSelectMariaDb3 =new MultSelectMariaDb(sql,operateMariaDb);
        MultSelectMariaDb multSelectMariaDb4 =new MultSelectMariaDb(sql,operateMariaDb);
        MultSelectMariaDb multSelectMariaDb5 =new MultSelectMariaDb(sql,operateMariaDb);
        MultSelectMariaDb multSelectMariaDb6 =new MultSelectMariaDb(sql,operateMariaDb);
        MultSelectMariaDb multSelectMariaDb7 =new MultSelectMariaDb(sql,operateMariaDb);
        MultSelectMariaDb multSelectMariaDb8 =new MultSelectMariaDb(sql,operateMariaDb);
        MultSelectMariaDb multSelectMariaDb9 =new MultSelectMariaDb(sql,operateMariaDb);
        MultSelectMariaDb multSelectMariaDb10 =new MultSelectMariaDb(sql,operateMariaDb);

        //将线程加入到查询线程组
        new Thread(selectGroup,multSelectMariaDb1).run();
        new Thread(selectGroup,multSelectMariaDb2).run();
        new Thread(selectGroup,multSelectMariaDb3).run();
        new Thread(selectGroup,multSelectMariaDb4).run();
        new Thread(selectGroup,multSelectMariaDb5).run();
        new Thread(selectGroup,multSelectMariaDb6).run();
        new Thread(selectGroup,multSelectMariaDb7).run();
        new Thread(selectGroup,multSelectMariaDb8).run();
        new Thread(selectGroup,multSelectMariaDb9).run();
        new Thread(selectGroup,multSelectMariaDb10).run();

        return selectGroup.activeCount();
    }


    /**
     * @desc 一次请求启动10个线程转化为10次请求 插入操作
     * @param sql
     */
    public int multInsert(String sql,OperateMariaDb operateMariaDb){

        //创建插入线程组
        insertGroup = new ThreadGroup("insert group");

        MultInsertMariaDb multInsertMariaDb1 = new MultInsertMariaDb(sql,operateMariaDb);
        MultInsertMariaDb multInsertMariaDb2 = new MultInsertMariaDb(sql,operateMariaDb);
        MultInsertMariaDb multInsertMariaDb3 = new MultInsertMariaDb(sql,operateMariaDb);
        MultInsertMariaDb multInsertMariaDb4 = new MultInsertMariaDb(sql,operateMariaDb);
        MultInsertMariaDb multInsertMariaDb5 = new MultInsertMariaDb(sql,operateMariaDb);
        MultInsertMariaDb multInsertMariaDb6 = new MultInsertMariaDb(sql,operateMariaDb);
        MultInsertMariaDb multInsertMariaDb7 = new MultInsertMariaDb(sql,operateMariaDb);
        MultInsertMariaDb multInsertMariaDb8 = new MultInsertMariaDb(sql,operateMariaDb);
        MultInsertMariaDb multInsertMariaDb9 = new MultInsertMariaDb(sql,operateMariaDb);
        MultInsertMariaDb multInsertMariaDb10 = new MultInsertMariaDb(sql,operateMariaDb);

        //将线程加入到插入线程组
        new Thread(insertGroup,multInsertMariaDb1).run();
        new Thread(insertGroup,multInsertMariaDb2).run();
        new Thread(insertGroup,multInsertMariaDb3).run();
        new Thread(insertGroup,multInsertMariaDb4).run();
        new Thread(insertGroup,multInsertMariaDb5).run();
        new Thread(insertGroup,multInsertMariaDb6).run();
        new Thread(insertGroup,multInsertMariaDb7).run();
        new Thread(insertGroup,multInsertMariaDb8).run();
        new Thread(insertGroup,multInsertMariaDb9).run();
        new Thread(insertGroup,multInsertMariaDb10).run();

       return insertGroup.activeCount();
    }

}
